import React, { useContext, useEffect } from 'react';
import { AuthContext } from './AuthContext';
import { useNavigation } from '@react-navigation/native';

const AuthGuard = ({ children }) => {
    const { userToken } = useContext(AuthContext);
    const navigation = useNavigation();

    useEffect(() => {
        if (!userToken) {
            navigation.replace('LoginPage');
        }
    }, [userToken, navigation]);

    if (!userToken) return null;

    return children;
};

export default AuthGuard; 